package org.aurora.core.server.scheduler.task;

import org.aurora.core.server.expression.Expression;
import org.aurora.model.entity.ScheduleTask;
import org.aurora.model.entity.Task;
import org.aurora.model.type.TaskTriggerType;

import java.util.Date;

public class TaskWrapper {
    private Task task;

    private Expression expression;

    public TaskWrapper(Task task, Expression expression) {
        this.task = task;
        this.expression = expression;
    }

    public Task getTask() {
        return task;
    }

    public void setTask(Task task) {
        this.task = task;
    }

    public Expression getExpression() {
        return expression;
    }

    public void setExpression(Expression expression) {
        this.expression = expression;
    }

    public ScheduleTask getNextSchedulerTask(TaskTriggerType taskTriggerType, Date date) {
        ScheduleTask scheduleTask = new ScheduleTask(task, taskTriggerType.getCode());
        scheduleTask.setExpectedSchedulerTime(expression.getNextValidTimeAfter(date));
        return scheduleTask;
    }
}
